//服务id
var serviceid = globalFun.GetQueryString('id');
var fromApp=globalFun.GetQueryString("from");
var isAnli = globalFun.GetQueryString('isAnli')
//var advisorId = 10;
//var uuid = '5895e62d36874626828b947e707a0484';
//var phone = 13717847870;
console.log(isAnli)
//是否切换到案例
if (isAnli) {
  // tips(111);
  $('.caseHe').show();
  $('#orderDetails').hide();
  $('.relatedGoods-list').hide();
  $('#case').addClass('aaa');
  $('#case').siblings().removeClass('aaa');
}
//切换tab
$('#service').on('click', function() {
  $('#orderDetails').show();
  $('.relatedGoods-list').hide();
  $('.caseHe').hide();
  $(this).addClass('aaa');
  $(this).siblings().removeClass('aaa');
})
$('#commodity').on('click', function() {
  $('.relatedGoods-list').show();
  $('#orderDetails').hide();
  $('.caseHe').hide();
  $(this).addClass('aaa');
  $(this).siblings().removeClass('aaa');
})
$('#case').on('click', function() {
  $('.caseHe').show();
  $('#orderDetails').hide();
  $('.relatedGoods-list').hide();
  $(this).addClass('aaa');
  $(this).siblings().removeClass('aaa');
})
//返回
$(".headaL").click(function() {
  if(!fromApp){
    window.history.back(-1);
  }else{
  if (mark===1) {
    setupWebViewJavascriptBridge(function(bridge){
      bridge.callHandler('goBack',function(resp){});
  });
    } else if (mark===0) {
           //var result = lase;
           window.stub.goBack();//用接口stub, 通过调用内部类中的方法jsMethod给javas传回result。

      }
  }
});

//服务列表

var title;
var content;
var bid;

var dataObj = {
		advisorId:serviceid,
 		memberId:''
}

if(Auth()){
		dataObj.memberId = user_info.id
}

$.ajax({
  type: "post",
     	url:apicom+"mobile/view/serviceProject/getServiceAdvisorMsg",
//url: "http://192.168.30.225:10001/mobile/view/serviceProject/getServiceAdvisorMsg",
  data:dataObj,
  async: false,
  dataType: "json",
  success: function(res) {
    if (typeof(res) == 'string') {
      res = JSON.parse(res);
    }
    console.log(res);
    if (res.code == 1) {
      var data = res.content;
      var aa = '';
      var bb = '';
      var cc = '';

      //关注
      if (res.content.folowStatus == 2) { //未关注
        $('.attention').html('关注')
        $('.attention').attr('type', '0')
      } else if (res.content.folowStatus == 0) { //已关注
        $('.attention').html('关注')
        $('.attention').attr('type', '0')
      } else{
      	$('.attention').html('已关注')
        $('.attention').attr('type', '1')
      }
      $('.head-tx img').attr('src', data.imgAddress);
      $('.blacklunbo-a img').attr('src', data.imgAddress);
      $('.head-mc').html(data.name);
      $('.main-aa').html(data.content);

      title = data.name;
      content = data.content;
      bid = data.memberId;

      if (data.starNum == null || data.starNum == 0) {
        $('.head-star').hide();
      } else {
        for (var ii = 1; ii < 6; ii++) {
          if (ii < data.starNum + 1) {
            $('.start' + ii).attr('src', '../../img/d_staryou.png');
          } else {
            $('.start' + ii).attr('src', '../../img/d_starwu.png');
          }
        }
      }


      /*if (data.starNum == 1) {
        $('.start1').attr('src', '../../img/d_staryou.png');
        $('.start2').attr('src', '../../img/d_starwu.png');
        $('.start3').attr('src', '../../img/d_starwu.png');
        $('.start4').attr('src', '../../img/d_starwu.png');
        $('.start5').attr('src', '../../img/d_starwu.png');
      } else if (data.starNum == 2) {
        $('.start1').attr('src', '../../img/d_staryou.png');
        $('.start2').attr('src', '../../img/d_staryou.png');
        $('.start3').attr('src', '../../img/d_starwu.png');
        $('.start4').attr('src', '../../img/d_starwu.png');
        $('.start5').attr('src', '../../img/d_starwu.png');
      } else if (data.starNum == 3) {
        $('.start1').attr('src', '../../img/d_staryou.png');
        $('.start2').attr('src', '../../img/d_staryou.png');
        $('.start3').attr('src', '../../img/d_staryou.png');
        $('.start4').attr('src', '../../img/d_starwu.png');
        $('.start5').attr('src', '../../img/d_starwu.png');
      } else if (data.starNum == 4) {
        $('.start1').attr('src', '../../img/d_staryou.png');
        $('.start2').attr('src', '../../img/d_staryou.png');
        $('.start3').attr('src', '../../img/d_staryou.png');
        $('.start4').attr('src', '../../img/d_staryou.png');
        $('.start5').attr('src', '../../img/d_starwu.png');
      } else if (data.starNum == 5) {
        $('.start1').attr('src', '../../img/d_staryou.png');
        $('.start2').attr('src', '../../img/d_staryou.png');
        $('.start3').attr('src', '../../img/d_staryou.png');
        $('.start4').attr('src', '../../img/d_staryou.png');
        $('.start5').attr('src', '../../img/d_staryou.png');
      }*/
      $('.main-dz').html(data.provinceName + data.cityName + data.countyName + data.address);
      $('.main-fensi').html(data.gzNumBy);
      $('.main-guanzhu').html(data.gzNum);
      //案例列表
      for (var j = 0; j < data.caseList.length; j++) {
        aa += '<li good-alid=' + data.caseList[j].caseId + ' ><p class="caseHeWen">' + data.caseList[j].title + '</p><div class="case-pic"><img src="' + data.caseList[j].address + '"/></div></li>'
      }
      $('.caseHe').html(aa);
      //商品列表
      for (var j = 0; j < data.productList.length; j++) {
        cc += '<li sp-id=' + data.productList[j].id + '><div class="relatedGoodsL-pic"><img src="' + data.productList[j].img + '"/></div><p class="relatedGoodsL-mc">' + data.productList[j].NAME + '</p><p class="relatedGoodsL-js">' + data.productList[j].title + '</p>'
        if(data.productList[j].minP==data.productList[j].maxP){
          cc+='<p class="relatedGoodsL-jg">¥<span class="relatedGoodsL-jq">' + data.productList[j].minP + '</span></p></li>'
        }else{
          cc+='<p class="relatedGoodsL-jg">¥<span class="relatedGoodsL-jq">' + data.productList[j].minP + '-' + data.productList[j].maxP + '</span></p></li>'
        }

      }
      $('.relatedGoods-list').html(cc);
      //服务列表
      for (var j = 0; j < data.serviceList.length; j++) {
        bb += '<li fw-id=' + data.serviceList[j].serviceId + '><div class="service-img"><img src="' + data.serviceList[j].serviceImgAddress + '"/><div class="service-mb"><p class="serviceMb-zuo">' + data.serviceList[j].title + '</p><p class="serviceMb-you">¥<span  class="service-rmb">' + data.serviceList[j].price + '</p></div></div></li>'
      }
      $('#orderDetails').html(bb);
    } else {
      tips(res.msg)
    }
  },
  error: function(err) {
    console.log(err);
  }
})

//服务列表跳转详情页
$('#orderDetails').on('click', 'li', function() {
	sessionStorage.setItem("fromHTML","H5");
  var id = $(this).attr('fw-id');
  window.location.href = '../homektxq/home_fwxq.html?id=' + id
})
//商品列表跳转到商品详情
$('.relatedGoods-list').on('click', 'li', function() {
  var id = $(this).attr('sp-id');
  window.location.href = '../shopDetail/shopDetail.html?id=' + id
})
//案例列表跳转到案例详情
$('.caseHe').on('click', 'li', function() {
  var id = $(this).attr('good-alid');
  window.location.href = '../service/detailsCase.html?id=' + id
})


/* 关注 */
function attention(id,type) {
  if (Auth()) {
    var dataObj = {
      bid: bid,
      type: type,
      uuid:user_info.uuid,
      phone:user_info.phone,
    }
  } else {
    toClientLogin(location.href);
    return false;
  }
  $.ajax({
      		url: apicom + "mobile/after/memberfollow/collect",
//  url: "http://192.168.30.225:10001/mobile/after/memberfollow/collect",
    type: 'POST',
    dataType: 'json',
    data: dataObj,
    success: function(result) {
      var res;
      if (typeof(result) == "string") {
        res = JSON.parse(result);
      } else {
        res = result
      }
      if (res.code == 1) {
        //提示
        layer.open({
          content: res.msg,
          skin: 'msg',
          time: 2 //2秒后自动关闭
        });


        if (type == 0) {
          $('.follow').html('已关注')
          $('.follow').attr('type', '1');
        } else if (type == 1) {
          $('.follow').html('关注');
          $('.follow').attr('type', '0');
        }
        $('.follow').removeClass('attention');
        setTimeout(function() {
          $('.follow').addClass('attention');
        }, 2000)
      } else {
        tips(res.msg);
      };
    },
    error: function(err) {
      tips("服务器错误！");
    }
  })
}


$(document).on('click', '.attention', function() {
  var type = $(this).attr('type');
  if (type == 0) {
    attention(serviceid, 0)
  } else {
    attention(serviceid, 1)
  }
})

//点击放大 头像
$('.head-tx').on('click', function() {
  $('.blacklunbo').show();
})
$('.blacklunbo').on('click', function() {
  $(this).hide();
})




var ua = navigator.userAgent.toLowerCase();

//分享
function zhuanfa(data) {
  if (/pjyc_i/.test(ua)) {
    setupWebViewJavascriptBridge(function(bridge) {
      bridge.callHandler('jsToClientShare', data, function(resp) {});
    });
  } else if (/pujiyicheng/.test(ua)) {
  	 var data2 = JSON.stringify(data);
    //var result = lase;
    window.stub.jsToClientShare(data2); //用接口stub, 通过调用内部类中的方法jsMethod给java传回result。

  }
}

$('.headaR').on('click', function() {
    	if(Auth()){
    		var data = {
    			uuid:user_info.uuid,
    			phone:user_info.phone,
    			memberId:user_info.id
    		}

    	} else{
    		sessionStorage.setItem('history', window.location.href);
    		toClientLogin(location.href)
    	}

    		var $self = $(this)
    		if($self.hasClass("disabled")){
    			return false
    		}
    		$self.addClass("disabled")
    		setTimeout(function(){
    			$self.removeClass("disabled")
    		},1000)

	  var data = {
	    type: 1,
	    url:location.href + '&share=' + user_info.id,
	    title: title,
	    content:content ,
	    //			hunterId:hunterId
	  }
	  zhuanfa(data);
	})

	/* 分享回调 */
	function shareCallBack(id){
		var dataObj={
			type:1,
			id:id,
			phone:user_info.phone,
			uuid:user_info.uuid
		}
		$.ajax({
				url: apicom + "mobile/after/share/share",
				type: 'POST',
				dataType: 'json',
				data: dataObj,
				success:function(result){
					var res;
					if(typeof(result) == "string"){
						res = JSON.parse(result);
					}else{
						res = result
					}
					if(res.code == 1){
						//需要进行的操作
					}
				},
				error:function(){
					//提示
					layer.open({
					    content: '服务器连接失败'
					    ,skin: 'msg'
					    ,time: 2 //2秒后自动关闭
					});
				}
			})
	}
